extends Panel
class_name UIDialog ##UI弹窗

@onready var context: Label = $VBoxContainer/Context
@onready var restart_button: Button = $VBoxContainer/VBoxContainer/RestartButton
@onready var option_button: Button = $VBoxContainer/VBoxContainer/OptionButton
@onready var back_button: Button = $VBoxContainer/VBoxContainer/BackButton

func _ready() -> void:
	GlobalSignals.game_status_game_over_signal.connect(_on_game_over_panel)
	restart_button.pressed.connect(_on_restart_button_pressed)
	option_button.pressed.connect(_on_option_button_pressed)
	back_button.pressed.connect(_on_back_button_pressed)

## 显示面板
func _on_game_over_panel(winSide:BoardCommon.TURN) -> void:
	var sideStr:String = "红方" if winSide == BoardCommon.TURN.RED else "黑方"
	context.text="获胜方："+sideStr
	visible=true

## 重新开始
func _on_restart_button_pressed() -> void:
	get_tree().paused = false # 取消暂停游戏
	get_tree().reload_current_scene()

## 选项设置
func _on_option_button_pressed() -> void:
	get_tree().change_scene_to_file("res://Main.tscn")

## 返回主菜单
func _on_back_button_pressed() -> void:
	get_tree().paused = false # 取消暂停游戏
	get_tree().change_scene_to_file("res://Main.tscn")
	
